﻿using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace Quickly.Identity.EntityFrameworkCore;

public class QuickIdentityDbContext
    : QuickIdentityDbContext<AppUser, AppRole, IdentityUserClaim<string>, IdentityUserRole<string>, IdentityUserLogin<string>, IdentityRoleClaim<string>, IdentityUserToken<string>>
{
    public QuickIdentityDbContext(DbContextOptions options) : base(options) { }

    protected QuickIdentityDbContext() { }
}

public class QuickIdentityDbContext<TUser>
    : QuickIdentityDbContext<TUser, AppRole, IdentityUserClaim<string>, IdentityUserRole<string>, IdentityUserLogin<string>, IdentityRoleClaim<string>, IdentityUserToken<string>>
    where TUser : AppUser
{
    public QuickIdentityDbContext(DbContextOptions options) : base(options) { }

    protected QuickIdentityDbContext() { }
}

public class QuickIdentityDbContext<TUser, TRole>
    : QuickIdentityDbContext<TUser, TRole, IdentityUserClaim<string>, IdentityUserRole<string>, IdentityUserLogin<string>, IdentityRoleClaim<string>, IdentityUserToken<string>>
    where TUser : AppUser
    where TRole : AppRole
{
    public QuickIdentityDbContext(DbContextOptions options) : base(options) { }

    protected QuickIdentityDbContext() { }
}

public class QuickIdentityDbContext<TUser, TRole, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>
    : IdentityDbContext<TUser, TRole, string, TUserClaim, TUserRole, TUserLogin, TRoleClaim, TUserToken>
    where TUser : AppUser
    where TRole : AppRole
    where TUserClaim : IdentityUserClaim<string>
    where TUserRole : IdentityUserRole<string>
    where TUserLogin : IdentityUserLogin<string>
    where TRoleClaim : IdentityRoleClaim<string>
    where TUserToken : IdentityUserToken<string>
{
    public QuickIdentityDbContext(DbContextOptions options) : base(options) { }

    public QuickIdentityDbContext() : base() { }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);

        builder.Entity<TUser>().ToTable("AppUsers");
        builder.Entity<TRole>().ToTable("AppRoles");
        builder.Entity<TUserClaim>().ToTable("AppUserClaims");
        builder.Entity<TUserRole>().ToTable("AppUserRoles");
        builder.Entity<TUserLogin>().ToTable("AppUserLogins");
        builder.Entity<TRoleClaim>().ToTable("AppRoleClaims");
        builder.Entity<TUserToken>().ToTable("AppUserTokens");
    }
}
